import router from "../router";
import { useUserStore } from "@/store/user";

export function logout(before?: () => void, after?: () => void) {
  const store = useUserStore();

  before && before();

  localStorage.removeItem("token");

  store.routes.forEach((item) => router.removeRoute(item.name));

  store.username = "";

  store.menus = [];

  router.push("/login");

  after && after();
}
